<?php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Model\Entity\Project;
use Application\Model\Entity\User;

class ProjectController extends AbstractActionController
{
    protected $_objectManager;
    
    public function indexAction()
    {        
              
        $projects = $this->getObjectManager()->getRepository('\Application\Model\Entity\Project')->findAll();
        $users = $this->getObjectManager()->getRepository('\Application\Model\Entity\User')->findAll();
        
        return new ViewModel(array(
            'projects' => $projects,
            'users'    => $users,
            )
        );      
    }
    
    public function showAction()
    {
        var_dump('show'); die();
//        $id = (int) $this->params()->fromRoute('id', 0);
//        $project = $this->getObjectManager()->find('\Application\Model\Entity\Project', $id);
//        if($project) {
//            return new ViewModel($project);
//        } else {
//            //echo $this->_forward("error");
//            $this->getResponse()->setStatusCode(404);
//            return;
//        }
    }


    protected function getObjectManager()
    {
        if (!$this->_objectManager) {
            $this->_objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        }

        return $this->_objectManager;
    }
    
    
}